//
//  FDMSearchTableViewCellSectionOne.m
//  Entertainment
//
//  Created by dllo on 16/4/27.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "FDMSearchTableViewCellSectionOne.h"
#import "FDMSearchDetailUserModel.h"

@interface FDMSearchTableViewCellSectionOne ()

@property (nonatomic, retain) UIImageView *titleImage;
@property (nonatomic, retain) FDMBaseLabel *titleLabel;
@property (nonatomic, retain) FDMBaseLabel *subTitleLabel;
@property (nonatomic, retain) FDMBaseLabel *trackCountLabel;
@property (nonatomic, retain) FDMBaseLabel *followingsCountLabel;

@end
@implementation FDMSearchTableViewCellSectionOne

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCell];
    }
    return self;
}

- (void)createCell {
    self.titleImage = [[UIImageView alloc] init];
    [self.contentView addSubview:self.titleImage];
    [self.titleImage release];
    self.titleLabel = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel release];
    self.subTitleLabel = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.subTitleLabel];
    [self.subTitleLabel release];
    self.trackCountLabel = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.trackCountLabel];
    [self.trackCountLabel release];
    self.followingsCountLabel = [[FDMBaseLabel alloc] init];
    [self.contentView addSubview:self.followingsCountLabel];
    [self.followingsCountLabel release];
    
}

- (void)dealloc {
    [self.titleImage release];
    [self.titleLabel release];
    [self.subTitleLabel release];
    [self.trackCountLabel release];
    [self.followingsCountLabel release];
    [super dealloc];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.titleImage.layer.cornerRadius = 40;
    self.titleImage.layer.masksToBounds = YES;
    [self.titleImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(10);
        make.left.equalTo(self.contentView.mas_left).with.offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-10);
        make.width.mas_equalTo(@80);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(10);
        make.left.equalTo(self.titleImage.mas_right).with.offset(10);
        make.bottom.equalTo(self.contentView.mas_top).with.offset(30);
        make.width.mas_equalTo(@(CONTENTVIEW_WIDTH - 110));
    }];
    self.subTitleLabel.textColor = [UIColor redColor];
    self.subTitleLabel.font = [UIFont systemFontOfSize:14];
    [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).with.offset(10);
        make.left.equalTo(self.titleImage.mas_right).with.offset(10);
        make.bottom.equalTo(self.titleLabel.mas_bottom).with.offset(30);
        make.width.mas_equalTo(@(CONTENTVIEW_WIDTH - 110));
    }];
    
    self.trackCountLabel.textColor = [UIColor grayColor];
    self.trackCountLabel.font = [UIFont systemFontOfSize:14];
    
    [self.trackCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.subTitleLabel.mas_bottom).with.offset(10);
        make.left.equalTo(self.titleImage.mas_right).with.offset(10);
        make.bottom.equalTo(self.subTitleLabel.mas_bottom).with.offset(20);
        make.width.mas_equalTo(@100);
    }];
    self.followingsCountLabel.textColor = [UIColor grayColor];
    self.followingsCountLabel.font = [UIFont systemFontOfSize:14];
    [self.followingsCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.subTitleLabel.mas_bottom).with.offset(10);
        make.left.equalTo(self.trackCountLabel.mas_right).with.offset(10);
        make.bottom.equalTo(self.subTitleLabel.mas_bottom).with.offset(20);
        make.width.mas_equalTo(@150);
    }];
}

- (void)setModel:(FDMSearchDetailUserModel *)model {
    if (_model != model) {
        [_model release];
        _model = [model retain];
        [self.titleImage sd_setImageWithURL:[NSURL URLWithString:_model.smallPic] placeholderImage:PLACEHOLDER_IMAGE];
        self.titleLabel.text = _model.nickname;
        self.subTitleLabel.text = _model.personDescribe;
        self.trackCountLabel.text = [NSString stringWithFormat:@"%@集", _model.tracks_counts];
        self.followingsCountLabel.text = [NSString stringWithFormat:@"粉丝%@", _model.followings_counts];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
